import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { Controller, Get, Post, Body, Param, NotFoundException } from '@nestjs/common';
import { UserService } from './user.service';
import { User } from './entities/user.entity';
@ApiTags('用户')
@Controller('users')
export class UserController {
  constructor(private readonly userService: UserService) {}

  // 创建用户
  @Post()
  createUser(@Body('name') name: string, @Body('email') email: string): Promise<User> {
    return this.userService.createUser(name, email);
  }

  // 查询所有用户
  @Get()
  getAllUsers(): Promise<User[]> {
    return this.userService.getAllUsers();
  }

  // 根据ID查询用户
  @Get(':id')
  async getUserById(@Param('id') id: number): Promise<User> {
    const user = await this.userService.getUserById(id);
    if (!user) {
      throw new NotFoundException('用户不存在');
    }
    return user;
  }
}